package com.cskaoyan.wordmemorize.controller.admin;


import com.cskaoyan.wordmemorize.aop_whh.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocChapterDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.VocChapterCommand;
import com.cskaoyan.wordmemorize.request.VocChapterPageRequest;
import com.cskaoyan.wordmemorize.service.VocChapterService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/voc")
public class ChaptersController {

    @Resource
    VocChapterService chaptersService;

    //分页查询章节列表
    @GetMapping("chapters/list")
    public Result<PageDTO<VocChapterDTO>> list(VocChapterPageRequest pageRequest) {
        PageDTO<VocChapterDTO> page = chaptersService.getChapterPage(pageRequest);
        return Result.ok(page);
    }
    //添加章节
    @OperateLog(dateType = "章节",operateType = 1)
    @PostMapping("chapter")
    public Result<String> addCategory(@RequestBody VocChapterCommand command) {
        chaptersService.addChapter(command);
        return Result.ok("success");
    }
    //修改章节
    @PutMapping("chapter")
    @OperateLog(dateType = "章节",operateType = 4)
    public Result<String> updateCategory(@RequestBody VocChapterCommand command) {
        chaptersService.updateChapter(command);
        return Result.ok("success");
    }
    //批量删除章节DELETE
    @OperateLog(dateType = "章节",operateType = 3)
    @DeleteMapping("chapters")
    public Result<String> deleteCategory(@RequestBody BatchDeleteCommand command) {
        chaptersService.deleteChapters(command);
        return Result.ok("success");
    }
    //删除指定章节
    @OperateLog(dateType = "章节",operateType = 2)
    @DeleteMapping("chapter/{chapterId}")
    public Result<String> deleteCategoryById(@PathVariable("chapterId") Long chapterId) {
        chaptersService.deleteChapter(chapterId);
        return Result.ok("success");
    }
}
